<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>倒计时</title>
	<style type="text/css">
        .time{
        	width:600px;height:300px;background: #999;margin:100px auto;
        }

        .time span{
        	padding:50px;line-height:300px;
        }
	</style>
	
</head>
<body>

    <div class="time">
        
	    <span id="t_d">00天</span>
	    <span id="t_h">00时</span>
	    <span id="t_m">00分</span>
	    <span id="t_s">00秒</span>
    </div>

    <script type="text/javascript">
        //计算现在到元旦的时间        
        function getTime(){
            //过去时间  从1970/01/01 00:00  开始计算至今
            //document.write("since 1970/01/01" +first.getTime()+"毫秒");
       	    var first = new Date();
            //现在时间
            var last = new Date('2018/01/01 00:00:00');         
            //时间差
            var t = last.getTime() - first.getTime();
           
            //初始化时间
            var s = 0;
            var m = 0;
            var h = 0;
            var d = 0;
            //判断
            if(t>=0){
           	             	
           	   d = Math.floor(t/1000/60/60/24);
           	   h = Math.floor(t/1000/60/60%24);
           	   m = Math.floor(t/1000/60%60);
           	   s = Math.floor(t/1000%60);

            }


           document.getElementById("t_d").innerHTML = d + "天";
           document.getElementById("t_h").innerHTML = h + "时";
           document.getElementById("t_m").innerHTML = m + "分";
           document.getElementById("t_s").innerHTML = s + "秒";

        }
        
        setInterval(getTime,0);
       
	</script>

   
</body>
</html>